AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')

function ENT:Initialize()
	self.Entity:SetModel("models/props_wasteland/light_spotlight01_lamp.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
	end
	util.PrecacheSound("weapons/c4/c4_beep1.wav")
	util.PrecacheSound("weapons/c4/c4_disarm.wav")
	util.PrecacheSound("weapons/c4/c4_explode1.wav")
	util.PrecacheSound("weapons/c4/c4_exp_deb1.wav")
	self.DidHit=false
end

function ENT:HitShit()
	self.Entity:GetPhysicsObject():Wake()
	self.DidHit = true
end

function ENT:Explode()
	if(self.Upgraded == true) then
	for k,v in pairs(player.GetAll()) do
			if v:IsPlayer() && v:GetPos():Distance(self.Entity:GetPos())<724 && v:GetNWBool("Snipe Shieldd")==true then
				v:SetNWBool("Snipe Shieldd", false)
				Notify(v, 4, 3, "The force of the Worldslayer shattered your shield!")
			end
		end
	end
	util.BlastDamage(self.Entity, self.Owner, self.Entity:GetPos(), 768, 700)
	local shake = ents.Create("env_shake")
		shake:SetOwner(self.Owner)
		shake:SetPos(self.Entity:GetPos())
		shake:SetKeyValue("amplitude", "2500")	// Power of the shake
		shake:SetKeyValue("radius", "3000")		// Radius of the shake
		shake:SetKeyValue("duration", "2.5")	// Time of shake
		shake:SetKeyValue("frequency", "255")	// How har should the screenshake be
		shake:SetKeyValue("spawnflags", "4")	// Spawnflags(In Air)
		shake:Spawn()
		shake:Activate()
		shake:Fire("StartShake", "", 0)
	local effectdata = EffectData()
		effectdata:SetStart(Vector(0,0,90))
		effectdata:SetOrigin(self.Entity:GetPos())
		effectdata:SetScale(3)
	util.Effect("effect_explosion_scaleable", effectdata)
	self.Entity:EmitSound(Sound("weapons/c4/c4_explode1.wav"))
	self.Entity:EmitSound(Sound("weapons/c4/c4_explode1.wav"))
	self.Entity:EmitSound(Sound("weapons/c4/c4_exp_deb1.wav"))
	for i=0, 10, 1 do
		local bomblet = ents.Create("bigbomb_fragment")
		local randpos = Vector(math.random(-5,5), math.random(-5,5), math.random(0,5))
		bomblet:SetOwner(self.Owner)
		bomblet:SetPhysicsAttacker(self.Owner)
		bomblet:SetPos(self.Entity:GetPos()+randpos)
		bomblet:Spawn()
		bomblet:Activate()
		bomblet:GetPhysicsObject():SetVelocity(randpos*50)
		bomblet.Owner = self.Owner
	end
	self.Entity:Remove()
end

function ENT:Touch()
	self.DidHit = true
end

function ENT:PhysicsUpdate()
	if (self.DidHit == true) then
		self.Entity:Explode()
	end
end

function ENT:PhysicsCollide(data, physobj)
	self.DidHit = true
end 